package com.cjbdi.service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.hibernate.SQLQuery;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cjbdi.util.NumUtil;



/**
 * EqTyService二期新增指数统一处理接口（独任、长期超审限、二审服判、调节结案、人民陪审）
 */
@Service
@Transactional
public class EqTyService{
	@Autowired
    Environment env;
	@Autowired  
    @PersistenceContext  
    private EntityManager entityManager;// 注入EntityManager实例 
	@Autowired
	BaseService baseService;
	//和去年同比
	public List getGsList(String table, String kind, String type, String date, String fybm){  
    	Query query = entityManager.createNativeQuery("select date,fymc,tnum,rnum,result from sfzs_result_"+table+" where type='"+type+"' and date in('"+date+"','"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"') and kind='"+kind+"' and jbfy='"+fybm+"' order by date desc");  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }
    //附表表格
    public List getFbList(String table, String type, String date, String fybm, String kind){  
    	StringBuffer sql = new StringBuffer("select distinct fyjc,tnum,rnum,result from sfzs_result_"+table+",sfzs_czrk where sfzs_result_"+table+".jbfy=sfzs_czrk.fybm and type='"+type+"' and sfzs_result_"+table+".date ='"+date+"' and sfzs_czrk.year='"+NumUtil.getPastDate(date,"yyyy")+"' and kind='"+kind+"' and ");
    	if(kind.equals("高")) {
    		sql.append("jbfy not in('X00','000','ZZ0')");
    	}else {
    		sql.append("jbfy like'"+fybm.substring(0, 1)+"%'");
    	}
    	if(!table.equals("cqcsx")) {
    		sql.append("order by result desc");
    	}else {
    		sql.append("order by result");
    	}
    	Query query = entityManager.createNativeQuery(sql.toString());  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        for(int i=0;i<rows.size();i++) {
			Map row = (Map)rows.get(i);
			row.put("id", i+1);
			row.put("lv", NumUtil.toNxiaoshu(row.get("result").toString(), 2)+"%");
		}
        return rows;
    }
    //全国排名表格
    /*public List getQgTableList(String table, String type, String date, boolean isQuanguo){  
    	StringBuffer sql = new StringBuffer("select jbfy,fy,lastyearzs,yearzs,cz,rank() over(order by yearzs");
    	if(!table.equals("cqcsx")) {
    		sql.append(" desc");
    	}	
    	sql.append(") as rank from(SELECT jbfy,fymc as fy,\r\n" + 
    			"sum(case when date='"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' then result else 0 end )as lastyearzs,\r\n" + 
    			"sum(case when date='"+date+"' then result else 0 end) as yearzs,\r\n" + 
    			"(sum(case when date='"+date+"' then result else 0 end) - sum(case when date='"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' then result else 0 end )) as cz from sfzs_result_"+table+" where (jbfy not in('X00','000') or jbfy is null)");
    	if(isQuanguo) {
    		sql.append(" and fymc='全国'");
    	}else {
    		sql.append(" and fymc!='全国'");
    	}
    	sql.append( " and type='"+type+"' and date in('"+date+"','"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"') and kind ='高' GROUP BY jbfy,fymc");
    	sql.append(")t");
    	Query query = entityManager.createNativeQuery(sql.toString());  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }*/
    //中院排名表格
    /*public List getZjTableList(String table, String type, String date, String fybm){  
    	StringBuffer sql = new StringBuffer("SELECT jbfy,fyjc as fy,\r\n" + 
        			"sum(case when date='"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' then result else 0 end )as lastyearzs,\r\n" + 
        			"sum(case when date='"+date+"' then result else 0 end) as yearzs,\r\n" + 
        			"(sum(case when date='"+date+"' then result else 0 end) - sum(case when date='"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' then result else 0 end )) as cz from sfzs_result_"+table+",sfzs_czrk where sfzs_result_"+table+".jbfy=sfzs_czrk.fybm and type='"+type+"' and sfzs_czrk.year='"+NumUtil.getPastDate(date,"yyyy")+"'and date in('"+date+"','"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"') and kind ='中' and jbfy like'"+fybm.substring(0, 1)+"%' GROUP BY jbfy,fyjc ORDER BY yearzs");
    	if(!table.equals("cqcsx")) {
    		sql.append(" desc");
    	}
    	Query query = entityManager.createNativeQuery(sql.toString());  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }*/
    //直辖市中院排名表格
    /*public List getZjZxTableList(String table, String type, String date, String fybm){  
    	StringBuffer sql = new StringBuffer( "SELECT\r\n" + 
    			"	jbfy,\r\n" + 
    			"	fyjc AS fy,\r\n" + 
    			"	sum( CASE WHEN date = '"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' THEN result ELSE 0 END ) AS lastyearzs,\r\n" + 
    			"	sum( CASE WHEN date = '"+date+"' THEN result ELSE 0 END ) AS yearzs,\r\n" + 
    			"	(\r\n" + 
    			"	sum( CASE WHEN date = '"+date+"' THEN result ELSE 0 END ) - sum( CASE WHEN date = '"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' THEN result ELSE 0 END ) \r\n" + 
    			"	) AS cz \r\n" + 
    			"FROM\r\n" + 
    			"	sfzs_result_"+table+",\r\n" + 
    			"	sfzs_czrk \r\n" + 
    			"WHERE\r\n" + 
    			"	sfzs_result_"+table+".jbfy = sfzs_czrk.fybm \r\n" + 
    			"	AND type = '"+type+"' \r\n" + 
    			"	AND sfzs_czrk.YEAR = '"+NumUtil.getPastDate(date,"yyyy")+"' \r\n" + 
    			"	AND kind = '辖'" + 
    			"	AND jbfy LIKE '"+fybm.substring(0, 1)+"%' AND right(jbfy,1)='0' AND jbfy <>'"+fybm.substring(0, 1)+"00'\r\n" + 
    			"GROUP BY\r\n" + 
    			"	jbfy,\r\n" + 
    			"	fyjc \r\n" + 
    			"ORDER BY\r\n" + 
    			"	yearzs");
    	if(!table.equals("cqcsx")) {
    		sql.append(" desc");
    	}
    	Query query = entityManager.createNativeQuery(sql.toString());  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }*/
    //辖区排名表格
    /*public List getXqTableList(String table, String type, String date, String fybm){  
    	StringBuffer sql = new StringBuffer("SELECT jbfy,replace(fymc,'人民法院','法院') as fy,\r\n" + 
    			"sum(case when date='"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' then result else 0 end )as lastyearzs,\r\n" + 
    			"sum(case when date='"+date+"' then result else 0 end) as yearzs,\r\n" + 
    			"(sum(case when date='"+date+"' then result else 0 end) - sum(case when date='"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' then result else 0 end )) as cz from sfzs_result_"+table+" where kind ='辖' and date in('"+date+"','"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"') and type ='"+type+"' and jbfy like'"+fybm.substring(0, 2)+"%' and jbfy<>'"+fybm.substring(0, 2)+"'||'0' and right(fymc,5)<>'（已撤销）' GROUP BY jbfy,fymc ORDER BY yearzs");
    	if(!table.equals("cqcsx")) {
    		sql.append(" desc");
    	}
    	Query query = entityManager.createNativeQuery(sql.toString());  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }*/

    //附表表格（区县）
    public List getFbQxList(String table, String type, String date, String fybm){  
    	StringBuffer sql = new StringBuffer("select replace(fymc,'人民法院','法院') as fyjc,tnum,rnum,result from sfzs_result_"+table+" where type='"+type+"' and sfzs_result_"+table+".date ='"+date+"' and kind='辖' and jbfy like'"+fybm.substring(0, 2)+"%' and right(fymc,5)<>'（已撤销）' order by result");
    	if(!table.equals("cqcsx")) {
    		sql.append(" desc");
    	}
    	Query query = entityManager.createNativeQuery(sql.toString());  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }
  //附表表格（区县本身）
    public List getFbQxSelfList(String table, String type, String date, String fybm){  
    	StringBuffer sql = new StringBuffer("select replace(fymc,'人民法院','法院') as fyjc,tnum,rnum,result from sfzs_result_"+table+" where type='"+type+"' and sfzs_result_"+table+".date ='"+date+"' and kind='辖' and jbfy ='"+fybm+"' order by result");
    	if(!table.equals("cqcsx")) {
    		sql.append(" desc");
    	}
    	Query query = entityManager.createNativeQuery(sql.toString());  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }
    //同等规模城市排名表格
    /*public List getTdZjTableList(String table, String type, String date, String fybm){  
    	StringBuffer sql = new StringBuffer("SELECT jbfy,replace(fyjc,'法院','')||'法院' AS fy,\r\n" + 
    			"sum(case when date='"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' then result else 0 end )as lastyearzs,\r\n" + 
    			"sum(case when date='"+date+"' then result else 0 end) as yearzs,\r\n" + 
    			"(sum(case when date='"+date+"' then result else 0 end) - sum(case when date='"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' then result else 0 end )) as cz from sfzs_result_"+table+",sfzs_czrk where sfzs_result_"+table+".jbfy=sfzs_czrk.fybm and type='"+type+"' and sfzs_czrk.year='"+NumUtil.getPastDate(date,"yyyy")+"' and (kind = '中' or (kind='高' and fybm in('100','200','900','M00'))) and size in (select size from sfzs_czrk where sfzs_czrk.year='"+NumUtil.getPastDate(date,"yyyy")+"' and fybm = '"+fybm+"') GROUP BY jbfy,fyjc ORDER BY yearzs");
    	if(!table.equals("cqcsx")) {
    		sql.append(" desc");
    	}
    	sql.append(" limit 20");
    	Query query = entityManager.createNativeQuery(sql.toString());  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }*/
    /*public List getTdZxTableList(String table, String type, String date, String fybm){  
    	StringBuffer sql = new StringBuffer("SELECT jbfy,fyjc as fy,\r\n" + 
    			"sum(case when date='"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' then result else 0 end )as lastyearzs,\r\n" + 
    			"sum(case when date='"+date+"' then result else 0 end) as yearzs,\r\n" + 
    			"(sum(case when date='"+date+"' then result else 0 end) - sum(case when date='"+NumUtil.getPastDate(date,"yyyy-MM-dd")+"' then result else 0 end )) as cz from sfzs_result_"+table+",sfzs_czrk where sfzs_result_"+table+".jbfy=sfzs_czrk.fybm and type='"+type+"' and sfzs_czrk.year='"+NumUtil.getPastDate(date,"yyyy")+"' and kind ='辖' AND (jbfy like'1%0' or jbfy like'2%0' or jbfy like'9%0' or jbfy like'M%0' )\r\n" + 
    					"	AND jbfy not in('100','200','900','M00') GROUP BY jbfy,fyjc ORDER BY yearzs");
    	if(!table.equals("cqcsx")) {
    		sql.append(" desc");
    	}
    	Query query = entityManager.createNativeQuery(sql.toString());  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }*/
    //同等收案量排名表格
    /*public List getTdSalTableList(String table, String type, String date, String fybm){  
    	StringBuffer sql = new StringBuffer("SELECT\r\n" + 
    			"	sal,jbfy,\r\n" + 
    			"	REPLACE ( fyjc, '法院', '' ) || '法院' AS fy,\r\n" + 
    			"	result\r\n" + 
    			"FROM sfzs_result_" + table+"," + 
    			"	sfzs_czrk \r\n" + 
    			"WHERE sfzs_result_" + 
    			table+".jbfy = sfzs_czrk.fybm \r\n" + 
    			"	AND type = '"+type+"' \r\n" + 
    			"	AND sfzs_czrk.YEAR = '"+NumUtil.getPastDate(date,"yyyy")+"' \r\n" + 
    			"	AND sfzs_result_"+table+".date = '"+date+"'\r\n" + 
    			"	AND kind = '中' \r\n" + 
    			"	AND sal IN ( SELECT sal FROM sfzs_czrk WHERE sfzs_czrk.YEAR = '"+NumUtil.getPastDate(date,"yyyy")+"' AND fybm = '"+fybm+"' ) \r\n");
    	if(!table.equals("cqcsx")) {
    		sql.append("ORDER BY result desc");
    	}else {
    		sql.append("ORDER BY result");
    	}
    	Query query = entityManager.createNativeQuery(sql.toString());  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }*/
    //区县法院基本信息
    /*public List getQxInfo(String table, String date, String fybm,String type){  
    	StringBuffer sql = new StringBuffer("select (select count(*) from sfzs_czrk where sfzs_czrk.year='"+NumUtil.getPastDate(date,"yyyy")+"' and size in (select size from sfzs_czrk where sfzs_czrk.year='"+NumUtil.getPastDate(date,"yyyy")+"' and fybm = '"+fybm+"')) as c,(select fyjc from sfzs_czrk where sfzs_czrk.year='"+NumUtil.getPastDate(date,"yyyy")+"' and fybm = '"+fybm.substring(0, 1)+"'||'00') as xq,num,jbfy,fy,rank,size from(select num,jbfy,fy,result,size,rank() over(order by result");
    	if(!table.equals("cqcsx")) {
    		sql.append(" desc");
    	}
    	sql.append(") as rank from(select size,num,jbfy,fyjc as fy,result from sfzs_result_"+table+",sfzs_czrk where sfzs_result_"+table+".jbfy=sfzs_czrk.fybm and type='"+type+"' and sfzs_czrk.year='"+NumUtil.getPastDate(date,"yyyy")+"' and kind ='中' and date='"+date+"' and size in (select size from sfzs_czrk where sfzs_czrk.year='"+NumUtil.getPastDate(date,"yyyy")+"' and fybm = '"+fybm+"')) t )t1 where jbfy='"+fybm+"'");
    	Query query = entityManager.createNativeQuery(sql.toString());  
        query.unwrap(SQLQuery.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);  
        List rows = query.getResultList();  
        return rows;
    }*/
    public void getEqTyzsGy(Map dataMap,String table, String kind, String type, String date, String fybm ,String fymc) {
    	getSectionOne(dataMap, table, kind, type, date, fybm);
    	List qgTableList = new ArrayList();
		List qgSelfList = new ArrayList();
    	if(table.equals("cqcsx")) {
    		qgTableList = baseService.getQgTableList("sfzs_result_"+table, type, date, false, false,"");
    		qgSelfList = baseService.getQgTableList("sfzs_result_"+table, type, date, true, false,"");
		}else {
			qgTableList = baseService.getQgTableList("sfzs_result_"+table, type, date, false, true,"");
			qgSelfList = baseService.getQgTableList("sfzs_result_"+table, type, date, true, true,"");
		}
		List qgTableList3 = new ArrayList();
		String rankQG1 = "";
		Map rowSelf = new HashMap();
		for(int i=qgTableList.size()-1;i>=0;i--) {//为全国报告增加
			Map row = (Map)qgTableList.get(i);
			String fy = row.get("fy").toString();
			if(fy.contains("北京")||fy.contains("天津")||fy.contains("上海")||fy.contains("重庆")) {//取第一个不是直辖市的高院
				continue;
			}else {
				rankQG1 = NumUtil.toSheng(fy);
				dataMap.put("eqty_"+table+"zs_rank1_qg",rankQG1+"法院");
				if(fymc.equals("全国")) {
					List zjList = new ArrayList();
					if(table.equals("cqcsx")) {
						zjList = baseService.getZjTableList("sfzs_result_"+table, type, date, row.get("jbfy").toString(), false, "");
					}else {
						zjList = baseService.getZjTableList("sfzs_result_"+table, type, date, row.get("jbfy").toString(), true, "");
					}
					Map rowzj = (Map)zjList.get(0);
					String rankZJ1 = rowzj.get("fy").toString();
					dataMap.put("eqty_"+table+"zs_rank1_zj", rankZJ1);//中级排名第一
				}
				break;
			}
		}
		baseService.getGyDataIntoMap(dataMap, qgTableList, qgSelfList, qgTableList3, fymc, "eqty_"+table+"zs");
		List zjTableList = new ArrayList();
		if(table.equals("cqcsx")) {
			zjTableList = baseService.getZjTableList("sfzs_result_"+table, type, date, fybm, false, "");
		}else {
			zjTableList = baseService.getZjTableList("sfzs_result_"+table, type, date, fybm, true, "");
		}
		List gylist = baseService.getSelfZs("sfzs_result_"+table, type, date, fybm, "");
		baseService.getZyDetailDataIntoMap(dataMap, zjTableList, gylist, fymc, "eqty_"+table+"zs");
		
		//处理表格
		if(table.equals("duren")) {
			if(fymc.equals("全国")) {
				dataMap.put("array6",qgTableList);
				dataMap.put(13,rankQG1);
				List fbList = getFbList(table,type,date,fybm,"高");
				dataMap.put("array41",fbList);
			}else {
				List fbList = getFbList(table,type,date,fybm,"中");
				dataMap.put("array11",qgTableList3);
				dataMap.put("array12",zjTableList);
				dataMap.put("array42",fbList);
			}
		}else if(table.equals("cqcsx")) {
			if(fymc.equals("全国")) {
				dataMap.put("array7",qgTableList);
				dataMap.put(15,rankQG1);
				List fbList = getFbList(table,type,date,fybm,"高");
				dataMap.put("array42",fbList);
			}else {
				List fbList = getFbList(table,type,date,fybm,"中");
				dataMap.put("array13",qgTableList3);
				dataMap.put("array14",zjTableList);
				dataMap.put("array43",fbList);
			}
			
		}/*else if(table.equals("esfp")) {
			dataMap.put("array17",qgTableList);
			dataMap.put("array18",zjTableList);
			dataMap.put("array81",fbList);
		}*/else if(table.equals("tj")) {
			if(fymc.equals("全国")) {
				dataMap.put("array10",qgTableList);
				dataMap.put(21,rankQG1);
				List fbList = getFbList(table,type,date,fybm,"高");
				dataMap.put("array45",fbList);
			}else {
				List fbList = getFbList(table,type,date,fybm,"中");
				dataMap.put("array19",qgTableList3);
				dataMap.put("array20",zjTableList);
				dataMap.put("array46",fbList);
			}
			
		}else if(table.equals("psy")) {
			if(fymc.equals("全国")) {
				dataMap.put("array11",qgTableList);
				dataMap.put(23,rankQG1);
				List fbList = getFbList(table,type,date,fybm,"高");
				dataMap.put("array46",fbList);
			}else {
				List fbList = getFbList(table,type,date,fybm,"中");
				dataMap.put("array21",qgTableList3);
				dataMap.put("array22",zjTableList);
				dataMap.put("array47",fbList);
			}
			
		}
	}
    public void getEqTyzsZy(Map dataMap,String table,String kind, String type, String date, String fybm ,String fymc) {
    	
		List zjTableList = new ArrayList();
		List tdTableList = new ArrayList();
		List xqTableList = new ArrayList();
		List tsTableList = new ArrayList();
		if(table.equals("cqcsx")) {
			xqTableList = baseService.getXqTableList("sfzs_result_"+table, type, date, fybm, false, "");
			List zylist = baseService.getSelfZs("sfzs_result_"+table, type, date, fybm, "");
			baseService.getQxDetailDataIntoMap(dataMap, xqTableList, zylist, fymc, "eqty_"+table+"zs");
			tsTableList = baseService.getTsTableList("sfzs_result_"+table,type, date, fybm, false, "");
	        baseService.getTsDataIntoMap(dataMap, tsTableList, fybm, "eqty_"+table+"zs");
			
			if(fybm.startsWith("1")||fybm.startsWith("2")||fybm.startsWith("M")||fybm.startsWith("9")) {
				getSectionOne(dataMap, table, "辖", type, date, fybm);
				tdTableList = baseService.getTdZxTableList("sfzs_result_"+table, type, date, fybm, false, "");	
				baseService.getTdZxDataIntoMap(dataMap, tdTableList, fybm, "eqty_"+table+"zs");
				zjTableList = baseService.getZjZxTableList("sfzs_result_"+table, type, date, fybm, false, "");	
				baseService.getZyDataIntoMap(dataMap, zjTableList, fybm, "eqty_"+table+"zs");
			}else {
				getSectionOne(dataMap, table, kind, type, date, fybm);
				List infoList = baseService.getQxInfo("sfzs_result_"+table, type, date, fybm, false, "");
				tdTableList = baseService.getTdZjTableList("sfzs_result_"+table, type, date, fybm, false, "");
				baseService.getTdCityDataIntoMap(dataMap, infoList, tdTableList, "eqty_"+table+"zs",fybm);
				zjTableList = baseService.getZjTableList("sfzs_result_"+table, type, date, fybm, false, "");
				baseService.getZyDataIntoMap(dataMap, zjTableList, fybm, "eqty_"+table+"zs");
				//同等收案量排行
				List tdSalTableList = baseService.getTdSalTableList("sfzs_result_"+table, type, date, fybm, false, "");
				baseService.getTdSalDataIntoMap(dataMap, tdSalTableList, fymc,"eqty_"+table+"zs");
				
				
			}
		}else {
			xqTableList = baseService.getXqTableList("sfzs_result_"+table,type, date, fybm, true, "");
			List zylist = baseService.getSelfZs("sfzs_result_"+table, type, date, fybm, "");
			baseService.getQxDetailDataIntoMap(dataMap, xqTableList, zylist, fymc, "eqty_"+table+"zs");
			tsTableList = baseService.getTsTableList("sfzs_result_"+table,type, date, fybm, true, "");
	        baseService.getTsDataIntoMap(dataMap, tsTableList, fybm, "eqty_"+table+"zs");
			if(fybm.startsWith("1")||fybm.startsWith("2")||fybm.startsWith("M")||fybm.startsWith("9")) {
				if(!table.equals("duren")) {//直辖市没有独任案件
					getSectionOne(dataMap, table, "辖", type, date, fybm);
					tdTableList = baseService.getTdZxTableList("sfzs_result_"+table,type, date, fybm, true, "");
					baseService.getTdZxDataIntoMap(dataMap, tdTableList, fybm, "eqty_"+table+"zs");
					zjTableList = baseService.getZjZxTableList("sfzs_result_"+table, type, date, fybm, true, "");
					baseService.getZyDataIntoMap(dataMap, zjTableList, fybm, "eqty_"+table+"zs");
				}
			}else {
				getSectionOne(dataMap, table, kind, type, date, fybm);
				List infoList = baseService.getQxInfo("sfzs_result_"+table, type, date, fybm, true, "");
				tdTableList = baseService.getTdZjTableList("sfzs_result_"+table, type, date, fybm, true, "");
				baseService.getTdCityDataIntoMap(dataMap, infoList, tdTableList, "eqty_"+table+"zs",fybm);
				zjTableList = baseService.getZjTableList("sfzs_result_"+table, type, date, fybm, true, "");
				baseService.getZyDataIntoMap(dataMap, zjTableList, fybm, "eqty_"+table+"zs");
				//同等收案量排行
				List tdSalTableList = baseService.getTdSalTableList("sfzs_result_"+table, type, date, fybm, true, "");
				baseService.getTdSalDataIntoMap(dataMap, tdSalTableList, fymc,"eqty_"+table+"zs");
				
				
			}
		}
		
		
		List fbList = getFbQxList(table,type,date,fybm);
		baseService.handleFb(fbList, fymc);
		//处理表格
		if(table.equals("duren")) {	
			if(fybm.startsWith("1")||fybm.startsWith("2")||fybm.startsWith("M")||fybm.startsWith("9")) {//直辖市没有独任案件
				/*dataMap.put("array18",zjTableList);
				dataMap.put("array19",tdTableList);
				dataMap.put("array20",xqTableList);
				dataMap.put("array21",tsTableList);
				dataMap.put("array71",fbList); */
			}else {
				dataMap.put("array18",zjTableList);
				dataMap.put("array19",tdTableList);
				dataMap.put("array20",xqTableList);
				dataMap.put("array21",tsTableList);
				dataMap.put("array71",fbList); 
			}
		}else if(table.equals("cqcsx")) {
			if(fybm.startsWith("1")||fybm.startsWith("2")||fybm.startsWith("M")||fybm.startsWith("9")) {
				dataMap.put("array18",zjTableList);
				dataMap.put("array19",tdTableList);
				dataMap.put("array20",xqTableList);
				dataMap.put("array21",tsTableList);
				dataMap.put("array67",fbList); 
			}else {
				dataMap.put("array22",zjTableList);
				dataMap.put("array23",tdTableList);
				dataMap.put("array24",xqTableList);
				dataMap.put("array25",tsTableList);
				dataMap.put("array72",fbList); 
			}
		}/*else if(table.equals("esfp")) {
			dataMap.put("array7",zjTableList);
			dataMap.put("array8",tdTableList);
			dataMap.put("array9",xqTableList);
			//dataMap.put("array13",fbList);
		}*/else if(table.equals("tj")) {	
			if(fybm.startsWith("1")||fybm.startsWith("2")||fybm.startsWith("M")||fybm.startsWith("9")) {
				dataMap.put("array30",zjTableList);
				dataMap.put("array31",tdTableList);
				dataMap.put("array32",xqTableList);
				dataMap.put("array33",tsTableList);
				dataMap.put("array70",fbList); 
			}else {
				dataMap.put("array34",zjTableList);
				dataMap.put("array35",tdTableList);
				dataMap.put("array36",xqTableList);
				dataMap.put("array37",tsTableList);
				dataMap.put("array75",fbList); 
			}
		}else if(table.equals("psy")) {
			if(fybm.startsWith("1")||fybm.startsWith("2")||fybm.startsWith("M")||fybm.startsWith("9")) {
				dataMap.put("array34",zjTableList);
				dataMap.put("array35",tdTableList);
				dataMap.put("array36",xqTableList);
				dataMap.put("array37",tsTableList);
				dataMap.put("array71",fbList); 
			}else {
				dataMap.put("array38",zjTableList);
				dataMap.put("array39",tdTableList);
				dataMap.put("array40",xqTableList);
				dataMap.put("array41",tsTableList);
				dataMap.put("array76",fbList); 
			}
		} 
	}
    public void getQxZs(Map dataMap,String kind, String type, String date, String fybm , String table) {//区县法院指数
    	getSectionOne(dataMap, table, kind, type, date, fybm);
    	List xqTableList = new ArrayList();
    	if(table.equals("cqcsx")) {
    		xqTableList = baseService.getXqTableList("sfzs_result_"+table,type, date, fybm, false, "");
    	}else {
    		xqTableList = baseService.getXqTableList("sfzs_result_"+table,type, date, fybm, true, "");
    	} 
    	List gylist = baseService.getGyOrZyXqZs("sfzs_result_"+table, type, date, fybm, "","高");
    	List zylist = baseService.getGyOrZyXqZs("sfzs_result_"+table, type, date, fybm, "","中");
    	baseService.getQxDataIntoMap(dataMap, xqTableList, fybm, "eqty_"+table+"zs",gylist,zylist);
    	String ssxq_gy_rank = "--";
    	
    	List fbList = getFbQxSelfList(table,type,date,fybm);
		for(int i=0;i<fbList.size();i++) {
			Map row = (Map)fbList.get(i);
			row.put("id", i+1);
			row.put("lv", NumUtil.toNxiaoshu(row.get("result").toString(), 2)+"%");
		}
		
		List tsTableList = new ArrayList();
		if(table.equals("cqcsx")) {
			tsTableList = baseService.getTsTableList("sfzs_result_"+table,type, date, fybm, false, "");
        	baseService.getTsDataIntoMap(dataMap, tsTableList, fybm, "eqty_"+table+"zs");
		}else {
			tsTableList = baseService.getTsTableList("sfzs_result_"+table,type, date, fybm, true, "");
        	baseService.getTsDataIntoMap(dataMap, tsTableList, fybm, "eqty_"+table+"zs");
		}
		
    	if(table.equals("duren")) {
    		ssxq_gy_rank = baseService.getRankInGyxq("sfzs_result_"+table,type,date,fybm,true,"").get(0).toString();
    		dataMap.put("array8",xqTableList);
    		dataMap.put("array9",tsTableList);
    		dataMap.put("array35",fbList); 
    	}else if(table.equals("cqcsx")) {
    		ssxq_gy_rank = baseService.getRankInGyxq("sfzs_result_"+table,type,date,fybm,false,"").get(0).toString();
    		dataMap.put("array10",xqTableList);
    		dataMap.put("array11",tsTableList);
    		dataMap.put("array36",fbList); 
    	}else if(table.equals("tj")) {
    		ssxq_gy_rank = baseService.getRankInGyxq("sfzs_result_"+table,type,date,fybm,true,"").get(0).toString();
    		dataMap.put("array16",xqTableList);
    		dataMap.put("array17",tsTableList);
    		dataMap.put("array39",fbList); 
    	}else if(table.equals("psy")) {
    		ssxq_gy_rank = baseService.getRankInGyxq("sfzs_result_"+table,type,date,fybm,true,"").get(0).toString();
    		dataMap.put("array18",xqTableList);
    		dataMap.put("array19",tsTableList);
    		dataMap.put("array40",fbList); 
    	}
    	dataMap.put("eqty_"+table+"zs_rank_gy",  "第" + NumUtil.toChineseNum(ssxq_gy_rank) + "位");
    }
    public void getSectionOne(Map dataMap,String table, String kind,String type, String date, String fybm) {
    	dataMap.put("eqty_"+table+"zs", "--");
    	dataMap.put("eqty_"+table+"zs_tb", "--");//同比
    	dataMap.put("eqty_"+table+"zs_tnum", "--");
		dataMap.put("eqty_"+table+"zs_rnum", "--");
    	List gslist = getGsList(table,kind,type,date,fybm);
		if(gslist.size()>1) {
			Map mapYear = (Map)gslist.get(0);;
	    	Map mapLastYear = (Map)gslist.get(1);
	    	double zs = NumUtil.toNxiaoshu(mapYear.get("result").toString(), 2);
	    	double zsLastYear = NumUtil.toNxiaoshu(mapLastYear.get("result").toString(), 2);
	    	dataMap.put("eqty_"+table+"zs", zs);
        	if(zs>zsLastYear) {
    			dataMap.put("eqty_"+table+"zs_tb", "上升"+(NumUtil.toNxiaoshu(zs-zsLastYear,2)));//同比
    		}else if(zs<zsLastYear) {
    			dataMap.put("eqty_"+table+"zs_tb", "下降"+(NumUtil.toNxiaoshu(zsLastYear-zs,2)));//同比
    		}else {
    			dataMap.put("eqty_"+table+"zs_tb", "不变");//同比
    		}
			dataMap.put("eqty_"+table+"zs_tnum", NumUtil.toWan(Integer.parseInt((mapYear).get("tnum").toString())));
			dataMap.put("eqty_"+table+"zs_rnum", NumUtil.toWan(Integer.parseInt((mapYear).get("rnum").toString())));
		}
    }
}
